﻿Imports System.Reflection


Public Class SimpleDataFilterType(Of T)
    Inherits DataFilterTypeBase(Of T)

    Public Property Value() As Object
        Get
            Return Me.iValue
        End Get
        Set(ByVal value As Object)
            Me.iValue = value
        End Set
    End Property

    Public Sub New(ByVal TableName As String, ByVal FieldName As String)
        Me.iTable = TableName
        Me.iFieldName = FieldName
        Me.iValue = Nothing
    End Sub

    Public Sub New(ByVal TableName As String, ByVal FieldName As String, ByVal Value As String)
        Me.iTable = TableName
        Me.iFieldName = FieldName
        Me.iValue = Value
    End Sub

    Public Overrides Function ToString() As String
        Return Me.iFieldName & ":" & Me.iValue
    End Function

    Public Overrides Function GetSQL() As String
        Dim sql As String = ""
        If IsNothing(Me.iValue) Then
            sql = " ([" & Me.iTable.ToString & "].[" & Me.iFieldName & "] Is NULL) "
        ElseIf IsDate(Me.iValue.ToString) Then
            sql = " ([" & Me.iTable.ToString & "].[" & Me.iFieldName & "] Between " & _
                            "'" & Format(CType(Me.iValue.ToString, DateTime), "yyyy-MMM-dd") & " 00:00:00.000' AND " & _
                            "'" & Format(CType(Me.iValue.ToString, DateTime), "yyyy-MMM-dd") & " 23:59:59.999') "
        Else
            sql = " ([" & Me.iTable.ToString & "].[" & Me.iFieldName & "] = '" & Me.iValue & "') "
        End If
        Return sql
    End Function

End Class

